<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>设置我的资料</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layuiadmin/style/admin.css" media="all">

    <style>

        #demo1 {
            display: block;
            width: 102px;
            height: 102px;
        }

    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">设置我的资料</div>
                <div class="layui-card-body" pad15>

                    <%--                    <div class="layui-form" lay-filter="">--%>
                    <%--                        <div class="layui-form-item">--%>
                    <%--                            <label class="layui-form-label">我的角色</label>--%>
                    <%--                            <div class="layui-input-inline">--%>
                    <%--                                &lt;%&ndash;                                <select name="role" lay-verify="">&ndash;%&gt;--%>
                    <%--                                &lt;%&ndash;                                    <option value="1" selected>超级管理员</option>&ndash;%&gt;--%>
                    <%--                                &lt;%&ndash;                                    <option value="2" disabled>普通管理员</option>&ndash;%&gt;--%>
                    <%--                                &lt;%&ndash;                                    <option value="3" disabled>审核员</option>&ndash;%&gt;--%>
                    <%--                                &lt;%&ndash;                                    <option value="4" disabled>编辑人员</option>&ndash;%&gt;--%>
                    <%--                                &lt;%&ndash;                                </select>&ndash;%&gt;--%>
                    <%--                                ${applicationScope.user.occupationType}--%>
                    <%--                            </div>--%>
                    <%--                            &lt;%&ndash;                            <div class="layui-form-mid layui-word-aux">当前角色不可更改为其它角色</div>&ndash;%&gt;--%>
                    <%--                        </div>--%>
                    <%--                        <div class="layui-form-item">--%>
                    <%--                            <label class="layui-form-label">用户名</label>--%>
                    <%--                            <div class="layui-input-inline">--%>
                    <%--                                &lt;%&ndash;                                <input type="text" name="username" value="xianxin" readonly class="layui-input">&ndash;%&gt;--%>
                    <%--                                ${applicationScope.user.userPhone}--%>
                    <%--                            </div>--%>
                    <%--                            &lt;%&ndash;                            <div class="layui-form-mid layui-word-aux">不可修改。一般用于后台登入名</div>&ndash;%&gt;--%>
                    <%--                        </div>--%>
                    <%--                        <div class="layui-form-item">--%>
                    <%--                            <label class="layui-form-label">昵称</label>--%>
                    <%--                            <div class="layui-input-inline">--%>
                    <%--                                <input type="text" name="nickname" value="${applicationScope.user.userPhone}"--%>
                    <%--                                       lay-verify="nickname" autocomplete="off" placeholder="请输入昵称" class="layui-input">--%>
                    <%--                            </div>--%>
                    <%--                        </div>--%>

                    <%--                        <div class="layui-form-item">--%>
                    <%--                            <label class="layui-form-label">出生日期</label>--%>
                    <%--                            <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->--%>
                    <%--                                <input type="text" class="layui-input" id="addBirthday" lay-verify="required" name="birthday" autocomplete="off">--%>
                    <%--                            </div>--%>
                    <%--                        </div>--%>
                    <%--                        &lt;%&ndash;                        <div class="layui-form-item">&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                            <label class="layui-form-label">性别</label>&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                            <div class="layui-input-block">&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                                <input type="radio" name="sex" value="男" title="男">&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                                <input type="radio" name="sex" value="女" title="女" checked>&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                            </div>&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                        </div>&ndash;%&gt;--%>
                    <%--                        <div class="layui-form-item">--%>
                    <%--                            &lt;%&ndash;                            <label class="layui-form-label">头像</label>&ndash;%&gt;--%>
                    <%--                            &lt;%&ndash;                            <div class="layui-input-inline">&ndash;%&gt;--%>
                    <%--                            &lt;%&ndash;                                <input name="avatar" lay-verify="required" id="LAY_avatarSrc" placeholder="图片地址" value="http://cdn.layui.com/avatar/168.jpg" class="layui-input">&ndash;%&gt;--%>
                    <%--                            &lt;%&ndash;                            </div>&ndash;%&gt;--%>
                    <%--                            &lt;%&ndash;                            <div class="layui-input-inline layui-btn-container" style="width: auto;">&ndash;%&gt;--%>
                    <%--                            &lt;%&ndash;                                <button type="button" class="layui-btn layui-btn-primary" id="LAY_avatarUpload">&ndash;%&gt;--%>
                    <%--                            &lt;%&ndash;                                    <i class="layui-icon">&#xe67c;</i>上传图片&ndash;%&gt;--%>
                    <%--                            &lt;%&ndash;                                </button>&ndash;%&gt;--%>
                    <%--                            &lt;%&ndash;                                <button class="layui-btn layui-btn-primary" layadmin-event="avartatPreview">查看图片</button >&ndash;%&gt;--%>
                    <%--                            &lt;%&ndash;                            </div>&ndash;%&gt;--%>
                    <%--                            <input type="text" id="imgPath" name="imgPath" value="" hidden>--%>

                    <%--                            &lt;%&ndash;头像上传&ndash;%&gt;--%>
                    <%--                            <div class="layui-form-item" style="margin-left: 110px">--%>
                    <%--                                <div class="layui-inline">--%>
                    <%--                                    &lt;%&ndash;                    <div class="layui-upload">&ndash;%&gt;--%>
                    <%--                                    <button type="button" class="layui-btn" id="uploadImg">更换头像</button>--%>
                    <%--                                    &lt;%&ndash;                    </div>&ndash;%&gt;--%>
                    <%--                                </div>--%>
                    <%--                            </div>--%>

                    <%--                            &lt;%&ndash;            <div class="layui-form-item" >&ndash;%&gt;--%>
                    <%--                            &lt;%&ndash;                <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->&ndash;%&gt;--%>
                    <%--                            <div class="layui-upload-list" style="margin-left: 110px">--%>
                    <%--                                <img class="layui-upload-img" id="demo1">--%>
                    <%--                                <p id="demoText"></p>--%>
                    <%--                            </div>--%>
                    <%--                            &lt;%&ndash;                </div>&ndash;%&gt;--%>
                    <%--                            &lt;%&ndash;            </div>&ndash;%&gt;--%>
                    <%--                        </div>--%>
                    <%--                        &lt;%&ndash;                        <div class="layui-form-item">&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                            <label class="layui-form-label">手机</label>&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                            <div class="layui-input-inline">&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                                <input type="text" name="cellphone" value="" lay-verify="phone" autocomplete="off" class="layui-input">&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                            </div>&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                        </div>&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                        <div class="layui-form-item">&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                            <label class="layui-form-label">邮箱</label>&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                            <div class="layui-input-inline">&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                                <input type="text" name="email" value="" lay-verify="email" autocomplete="off" class="layui-input">&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                            </div>&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                        </div>&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                        <div class="layui-form-item layui-form-text">&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                            <label class="layui-form-label">备注</label>&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                            <div class="layui-input-block">&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                                <textarea name="remarks" placeholder="请输入内容" class="layui-textarea"></textarea>&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                            </div>&ndash;%&gt;--%>
                    <%--                        &lt;%&ndash;                        </div>&ndash;%&gt;--%>
                    <%--                        <div class="layui-form-item">--%>
                    <%--                            <div class="layui-input-block">--%>
                    <%--                                <button class="layui-btn" type="button" lay-submit lay-filter="setmyinfo">确认修改</button>--%>
                    <%--                                &lt;%&ndash;                                <button type="reset" class="layui-btn layui-btn-primary">重新填写</button>&ndash;%&gt;--%>
                    <%--                            </div>--%>
                    <%--                        </div>--%>
                    <%--                    </div>--%>

                    <form class="layui-form" lay-filter="addForm" id="addForm">
                        <%--                        <div class="layui-form-item">--%>
                        <%--                            <label class="layui-form-label">姓名</label>--%>
                        <%--                            <div class="layui-input-block">--%>
                        <%--                                <input type="text" name="userName" id="addUserName" required lay-verify="required"--%>
                        <%--                                       placeholder="请输入姓名"--%>
                        <%--                                       autocomplete="off" class="layui-input">--%>
                        <%--                            </div>--%>
                        <%--                        </div>--%>
                            <input hidden id="userId" name="id" value="${applicationScope.user.id}">
                        <div class="layui-form-item" id="occupationType">
                            <label class="layui-form-label">当前职位</label>
                            <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
                                <input type="text" value="${applicationScope.user.occupationType}"
                                       class="layui-input" readonly>

                                <div class="layui-form-mid layui-word-aux">职位不可修改</div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">昵称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="userNickname" id="addUserNickname" required
                                       value="${applicationScope.user.userNickname}"
                                       lay-verify="required"
                                       placeholder="请输入昵称"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <%--                        <div class="layui-form-item">--%>
                        <%--                            <label class="layui-form-label">系统密码</label>--%>
                        <%--                            <div class="layui-input-inline">--%>
                        <%--                                <input type="text" name="systemPassword" id="addSystemPassword" required lay-verify="required" placeholder="请输入密码"--%>
                        <%--                                       autocomplete="off" class="layui-input">--%>
                        <%--                            </div>--%>
                        <%--                        </div>--%>
                        <div class="layui-form-item">
                            <label class="layui-form-label">电话</label>
                            <div class="layui-input-inline">
                                <input type="text" name="userPhone" id="addUserPhone"
                                       value="${applicationScope.user.userPhone}" required lay-verify="required"
                                       placeholder="请输入密码"
                                       autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item" id="birthday">
                            <label class="layui-form-label">出生日期</label>
                            <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->
                                <input type="text" class="layui-input" id="addBirthday"
                                       value="<fmt:formatDate value='${applicationScope.user.birthday}' pattern='yyyy-MM-dd'/>" lay-verify="required"
                                       autocomplete="off" readonly>
                                <div class="layui-form-mid layui-word-aux">出生日期不可修改</div>
                            </div>
                        </div>

                        <%--                        <div class="layui-form-item">--%>
                        <%--                            <label class="layui-form-label">身份证</label>--%>
                        <%--                            <div class="layui-input-inline">--%>
                        <%--                                <input type="text" name="idCard" id="idCard" required lay-verify="required"  placeholder="请输入身份证信息"--%>
                        <%--                                       autocomplete="off" class="layui-input">--%>
                        <%--                            </div>--%>
                        <%--                        </div>--%>

                        <input type="text" id="imgPath" name="imgPath" hidden>

                        <%--头像上传--%>
                        <div class="layui-form-item" style="margin-left: 110px">
                            <div class="layui-inline">
                                <%--                    <div class="layui-upload">--%>
                                <button type="button" class="layui-btn" id="uploadImg">修改头像</button>
                                <%--                    </div>--%>
                            </div>
                        </div>

                        <%--            <div class="layui-form-item" >--%>
                        <%--                <div class="layui-inline"> <!-- 注意：这一层元素并不是必须的 -->--%>
                        <div class="layui-upload-list" style="margin-left: 110px">
                            <img class="layui-upload-img" id="demo1" src="${applicationScope.user.imgPath}">
                            <p id="demoText"></p>
                        </div>
                        <%--                </div>--%>
                        <%--            </div>--%>


                        <%--            <div class="layui-form-item">--%>
                        <%--                <label class="layui-form-label">状态</label>--%>
                        <%--                <div class="layui-input-block">--%>
                        <%--                    <select name="status" lay-verify="required" id="addStatus">--%>
                        <%--                        <option value="1">正常</option>--%>
                        <%--&lt;%&ndash;                        <option value="0">封禁</option>&ndash;%&gt;--%>
                        <%--                    </select>--%>
                        <%--                </div>--%>
                        <%--            </div>--%>


                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <%--                    <button class="layui-btn" type="button" id="addUserButton">添加用户</button>--%>
                                <button class="layui-btn" type="button" lay-submit lay-filter="addUserButton"
                                        id="addUserButton">确认修改
                                </button>
                                <%--                                <button type="reset" class="layui-btn layui-btn-primary">重置</button>--%>
                                <%--                                <button type="button" class="layui-btn layui-btn-primary" id="addReturnWindows">返回</button>--%>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${pageContext.request.contextPath}/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '${pageContext.request.contextPath}/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table', 'form', 'layer', 'laydate', 'upload'], function () {
        var table = layui.table,
            form = layui.form,
            layer = layui.layer,
            $ = layui.$,
            admin = layui.admin,
            laydate = layui.laydate
            , upload = layui.upload;

        $("#logout").click(function () {
            // console.log("logout");
            location.href = '${pageContext.request.contextPath}/user/logout'
        });

        var id = $("#userId").val();

        //更新用户信息
        form.on('submit(addUserButton)', function (data) {
            var data = data.field;
            // layer.msg(JSON.stringify(data.field));
            // console.log(data)
            $.ajax({
                url: "${pageContext.request.contextPath}/user/updateAllUserInfo",
                type: "post",
                data: JSON.stringify(data),
                contentType: 'application/json',
                processDate: false,
                success: function (res) {
                    if (res.code == 0){
                        form.render();
                        // userListTable.reload();
                        refreshPage();
                        parent.location.reload();
                        <%--location.href = '${pageContext.request.contextPath}/system/home';--%>
                        return;
                    }else {
                        form.render();
                        layer.msg(res.msg);
                    }

                    // return;
                }
            })
            // return false;
        });


        function refreshPage() {
            $.ajax({
                url: "${pageContext.request.contextPath}/system/refreshPage?id=" + id,
                type: "get",
                success: function (res) {
                    return;
                }
            })
        }



        //普通图片上传
        var uploadInst = upload.render({
            elem: '#uploadImg'
            , url: '${pageContext.request.contextPath}/file/upload' //改成您自己的上传接口
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                console.log(res);
                //如果上传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                } else {
                    $("#imgPath").val(res.data[0]);
                }
                //上传成功
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

        // $("#occupationType").hover(function () {
        //     layer.msg("当前角色职位不能修改");
        // });
        // $("#birthday").hover(function () {
        //     layer.msg("当前角色出生日期不能修改");
        // });

        laydate.render({
            elem: '#updateBirthday' //指定元素
        });

    })
</script>
</body>
</html>